package com.awspaas.user.apps.cpq.controller;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.bpms.util.DBSql;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.awspaas.user.apps.cpq.util.RefreshDataUtils;
import com.awspaas.user.apps.cpq.util.RefreshModulDataUtils;
import com.awspaas.user.apps.cpq.util.RefreshTempDataUtils;

public class CPQ_outsourcingRefreshPriceWeb {

	public String outsourcingRefreshPrice(UserContext userContext, String rowData) {
		try {
			JSONArray dataList = JSONObject.parseArray(rowData);
			// 获取需要更新的原材料编号。
		    Map<String, JSONObject> userMap = new HashMap<String, JSONObject>();
		    String bms = "";
			List<String> bhList = new ArrayList<>();
			for (int i = 0; i < dataList.size(); i++) {
				JSONObject jsonObject = (JSONObject) dataList.get(i);
				String bm = (String) jsonObject.get("BM");
					JSONObject json = new JSONObject();
					json.put("QTFY", (String) jsonObject.get("QTFY"));
					json.put("BM", bm);
					bhList.add(bm);
					userMap.put(bm, json);
					if (bms.isEmpty()) {
						bms = "'" + bms + "'";
					} else {
						bms += ",'" + bms + "'";
					}
			}
			/**
			 * 1、获取需要更新的制造件和装配件信息
			 */
			
			Map<String, JSONObject> comtMap=RefreshDataUtils.outsourcingRefreshAssembly‌(userMap);
			/**
			 * 2、获取需要更新的模块信息
			 * 
			 */
			
		   Map<String, Map<String, Object>> modulLists=RefreshModulDataUtils.outsourcingRefreshModule(comtMap);
			/**
			 * 3、获取需要更新的项目报价记录台账中类型为模板的数据
			 * 
			 */	
		 
			RefreshTempDataUtils.updateTempByOutsourcing‌(modulLists);
			 ResponseObject ro = ResponseObject.newOkResponse();
				return ro.toString();
		} catch (Exception e) {
			throw  e;
		}
	
	}

}
